import * as React from "react"; import { Provider, Flex, Text, Button, Header } from "@fluentui/react-northstar"; import { useState, useEffect } from "react"; import { useTeams } from "msteams-react-base-component"; import { app<% if (tabSSO) { %>, authentication<% } %> } from "@microsoft/teams-js";<% if (tabSSO) { %> import jwtDecode from "jwt-decode";<% } %> /** * Implementation of the <%= tabTitle %> content page */ export const <%=tabReactComponentName%> = () => { const [{ inTeams, theme, context }] = useTeams(); const [entityId, setEntityId] = useState();<% if (tabSSO) { %> const [name, setName] = useState(); const [error, setError] = useState();<% } %> useEffect(() => { if (inTeams === true) {<% if (tabSSO) { %> authentication.getAuthToken({ resources: [process.env.TAB_APP_URI as string], silent: false } as authentication.AuthTokenRequestParameters).then(token => { const decoded: { [key: string]: any; } = jwtDecode(token) as { [key: string]: any; }; setName(decoded!.name); app.notifySuccess(); }).catch(message => { setError(message); app.notifyFailure({ reason: app.FailedReason.AuthFailed, message }); });<% } else { %> app.notifySuccess();<% } %> } else { setEntityId("Not in Microsoft Teams"); } }, [inTeams]); useEffect(() => { if (context) { setEntityId(context.page.id); } }, [context]); /** * The render() method to create the UI of the tab */ return (
<% if (tabSSO) { %>
{error &&
} <% } else { %>
<% } %>
); };